package com.yumis.service.modules.car.service.Impl;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.exception.GlobalException;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.CarTaskTime;
import com.yumis.service.model.pojo.CategoryParts;
import com.yumis.service.modules.car.mapper.CategoryPartsMapper;
import com.yumis.service.modules.car.service.CategoryPartsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class CategoryPartsServiceImpl implements CategoryPartsService {
    @Resource
    private CategoryPartsMapper categoryPartsMapper;
    @Override
    public void addCategoryParts(CategoryParts categoryParts) {
        int i=categoryPartsMapper.insertSelective(categoryParts);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.CREATED_FAILED));
        }
    }

    @Override
    public void deleteCategoryPartsById(Long id) {
        int i=categoryPartsMapper.deleteByPrimaryKey(id);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.DELETE_ERROR));
        }
    }

    @Override
    public CategoryParts queryCategoryPartsById(Long id) {
        CategoryParts categoryParts=categoryPartsMapper.selectByPrimaryKey(id);
        if (categoryParts ==null || categoryParts.equals("") ){
            throw new GlobalException(Response.buildResponse(HttpState.DATA_NOT_FOUNT));
        }
        return categoryParts;
    }

    @Override
    public void updateCategoryParts(CategoryParts categoryParts) {
        int i=categoryPartsMapper.updateByPrimaryKeySelective(categoryParts);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.UPDATE_ERROR));
        }
    }
}
